<?php
class UserModule extends CWebModule {

	public $homeUrl = array("/home/index");
	
	public $registrationUrl = array("/user/registration");
	public $profileUrl = array("/user/profile");
	public $profilePasswordUrl = "/user/profile/password";
	
	public $recoveryUrl = array("/user/recovery/");
    public $activationUrl = array("/user/actiovation");
    
	public $hash='md5';    
    public $sendActivationEmail = true;
	public $approveByAdmin = false;

	const USERGROUP_CANDIDATE = 4;
	const USERGROUP_USER = 3;
	const DEFAULT_COUNTRY = 1;
	const DEFAULT_REGION = 1;
	

	public function init() {
        ///////fix for swfuploader!!!!
        //need check this thin place.
        if (isset($_POST['PHPSESSID'])) {
          $_COOKIE['PHPSESSID'] = $_POST['PHPSESSID'];
        }    
		$this->publishAssets();
        
		$this->setImport(array(
			'user.models.*',
			'user.components.*',
		));
	}

	public function beforeControllerAction($controller, $action) {
		if(parent::beforeControllerAction($controller, $action)) {
			// this method is called before any module controller action is performed
			// you may place customized code here
			return true;
		} else {
			return false;
        }    
	}
	
	protected static function publishAssets() {
		$assets=dirname(__FILE__).'/assets';
		$baseUrl=Yii::app()->assetManager->publish($assets);
		if(is_dir($assets)) {
//			Yii::app()->clientScript->registerScriptFile($baseUrl.'/some.js',CClientScript::POS_HEAD);
			Yii::app()->clientScript->registerCssFile($baseUrl.'/css/user.css');
		} else {
			throw new Exception('User module - Error: Couldn\'t find assets to publish.');
		}
	}	
    
	public static function encrypting($string='') {
		$hash = Yii::app()->getModule('user')->hash;
		if ($hash=="md5") 
			return md5($string);
		if ($hash=="sha1")
			return sha1($string);
		else
			return hash($hash,$string);
	}    
    
	public static function t($str='',$params=array(), $dic='user') {
		return Yii::t('UserModule.'.$dic, $str, $params);
	}    
    
    
	
}
